﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace shi_yan
{
    class Program
    {
        public static int js = 0;
        public static void TimerTest()
        {
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 3000;
            timer.AutoReset = false;
            timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            timer.Enabled = true;
        }
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            js = 1;
        }
        static void xs(int[,] map)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (map[i, j] == 0)
                    {
                        Console.Write("  ");
                    }
                    else if (map[i, j] == 1)
                    {
                        Console.Write("■");
                    }
                    else if (map[i, j] == 2)
                    {
                        Console.Write("☆");
                    }
                }
                Console.WriteLine();
            }
        }
        static void sj(int[,] map)
        {
            Random random = new Random();
            int i = random.Next(1, 3);
            map[1, i] = 2;
        }
        static void Main(string[] args)
        {
            int[,] map = new int[3, 4]{
                { 1, 1, 1, 1 },
                { 1, 0, 0, 1 },
                { 1, 1, 1, 1 } };
            int[,] StartMap = new int[3, 4]{
                { 1, 1, 1, 1 },
                { 1, 0, 0, 1 },
                { 1, 1, 1, 1 } };
            int score = 0;
            TimerTest();
            for (; ; )
            {
                Console.WriteLine("分数：" + score);
                if (js == 1)
                {
                    break;
                }
                sj(map);
                xs(map);
                ConsoleKeyInfo aj = Console.ReadKey();
                if (aj.Key.ToString() == "LeftArrow")
                {
                    if (map[1, 1] == 2)
                    {
                        score++;
                    }
                    else if (map[1, 1] == 0)
                    {
                        score--;
                    }
                }
                else if (aj.Key.ToString() == "RightArrow")
                {
                    if (map[1, 2] == 2)
                    {
                        score++;
                    }
                    else if (map[1, 2] == 0)
                    {
                        score--;
                    }
                }
                Array.Copy(StartMap, map, StartMap.Length);
                Console.Clear();
            }
            Console.Clear();
            Console.WriteLine("用时：3秒"+"分数："+score);
            Console.Read();

        }
    }
}
